﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using TpBaseObjects.Base;

namespace TpBaseObjects.Objects {

    public class PlzOrt : MyBaseModel, IEquatable<PlzOrt>, IComparable<PlzOrt> {

        #region Members

        private int eplz;
        private string lkz;
        private string plz;
        private string ort;
        private int zone;
        private int bundesland;

        #endregion

        #region Constructor

        public PlzOrt() {
        }

        #endregion

        #region Properties

        [DataMember]
        public int EPLZ {
            get { return this.eplz; }
            set {
                if (this.eplz == value) {
                    return;
                }
                this.eplz = value;
                OnPropertyChanged(() => EPLZ);
            }
        }
        
        [DataMember]
        public string Lkz {
            get { return this.lkz; }
            set {
                if (this.lkz == value) {
                    return;
                }
                this.lkz = value;
                OnPropertyChanged(() => Lkz);
            }
        }

        [DataMember]
        public string Plz {
            get { return this.plz; }
            set {
                if (this.plz == value) {
                    return;
                }
                this.plz = value;
                OnPropertyChanged(() => Plz);
            }
        }

        [DataMember]
        public string Ort {
            get { return this.ort; }
            set {
                if (this.ort == value) {
                    return;
                }
                this.ort = value;
                OnPropertyChanged(() => Ort);
            }
        }

        [DataMember]
        public int Zone {
            get { return this.zone; }
            set {
                if (this.zone == value) {
                    return;
                }
                this.zone = value;
                OnPropertyChanged(() => Zone);
            }
        }

        [DataMember]
        public int Bundesland {
            get { return this.bundesland; }
            set {
                if (this.bundesland == value) {
                    return;
                }
                this.bundesland = value;
                OnPropertyChanged(() => Bundesland);
            }
        }

        public string ZipCodeAndTown {
            get {
                return this.Plz + ' ' + this.Ort;
            }
        }

        #endregion

        #region Functions

        public int CompareTo(PlzOrt comparePart) {
            // A null value means that this object is greater.
            if (comparePart == null)
                return 1;

            else
                return this.Plz.CompareTo(comparePart.Plz);
        }

        public bool Equals(PlzOrt other) {
            if (other == null) return false;
            return (this.EPLZ.Equals(other.EPLZ));
        }

        #endregion

        #region Overide

        public override bool Equals(object obj) {
            if (obj == null) return false;
            PlzOrt objAsPart = obj as PlzOrt;
            if (objAsPart == null) return false;
            else return Equals(objAsPart);
        }

        public override int GetHashCode() {
            return this.EPLZ;
        }

        public override string ToString() {
            return "Plz: " + this.Plz.ToString() + "   Ort: " + this.Ort;
        }

        #endregion

    }
}
